package com.czg.designmode.state;

import java.util.Random;

/**
 * 投币状态类
 *
 * @author chenzhigang
 */
public class HasCoin implements State {

    private CandyMachine mCandyMachine;

    public HasCoin(CandyMachine mCandyMachine) {
        this.mCandyMachine = mCandyMachine;
    }

    @Override
    public void insertCoin() {
    }

    @Override
    public void returnCoin() {
        mCandyMachine.setState(mCandyMachine.mOnReadyState);
    }

    @Override
    public void turnCrank() {
        System.out.println("crank turn...!");
        Random ranWinner = new Random();
        int winner = ranWinner.nextInt(10);
        if (winner == 0) {
            mCandyMachine.setState(mCandyMachine.mWinnerState);
        } else {
            mCandyMachine.setState(mCandyMachine.mSoldState);
        }
    }

    @Override
    public void dispense() {
    }

    @Override
    public void printState() {
        System.out.println("***HasCoin***");
    }

}